﻿package mortal.game.view.mainUI.shortcutbar
{
    import Message.DB.Tables.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class ShortcutBarCache extends Object
    {
        private var _obj:Object;
        private var _lastKeyDownPos:int = -1;
        public var isLastKeyByClick:Boolean = false;
        public var isLocked:Boolean = false;
        public var isShowCDTime:Boolean = true;

        public function ShortcutBarCache()
        {
            this._obj = {};
            return;
        }// end function

        public function get lastKeyDownPos() : int
        {
            return this._lastKeyDownPos;
        }// end function

        public function set lastKeyDownPos(param1:int) : void
        {
            this._lastKeyDownPos = param1;
            return;
        }// end function

        public function initData(param1:String) : void
        {
            if (param1 == null || param1 == "")
            {
                return;
            }
            this._obj = JSON.parse(param1);
            this.checkAndSaveToCurCareerSkill();
            return;
        }// end function

        public function checkAndSaveToCurCareerSkill() : void
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:TSkill = null;
            if (this._obj == null)
            {
                return;
            }
            var _loc_1:Boolean = false;
            var _loc_2:* = Cache.instance.role.entityInfo.career;
            for each (_loc_3 in this._obj)
            {
                
                _loc_4 = _loc_3["t"];
                _loc_5 = _loc_3["v"];
                if (_loc_4 == CDDataType.skillInfo)
                {
                    _loc_6 = SkillConfig.instance.getFirstSkillBySerialId(_loc_5);
                    if (_loc_6 != null && !CareerUtil.isCareerSuit(_loc_6.career, _loc_2) && _loc_6.posType > 0)
                    {
                        _loc_6 = SkillConfig.instance.getSkillByPosAndCareer(_loc_6.posType, _loc_2);
                        if (_loc_6 != null)
                        {
                            _loc_3["v"] = _loc_6.series;
                            _loc_1 = true;
                        }
                    }
                }
            }
            if (_loc_1)
            {
                this.save();
            }
            return;
        }// end function

        public function get shortcutBarDatas() : Object
        {
            return this._obj;
        }// end function

        public function addShortCut(param1:int, param2:int, param3:Object) : void
        {
            this._obj[param1] = {t:param2, v:param3};
            var _loc_4:Object = {pos:param1, t:param2, v:param3};
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShortcutBarDataChange, _loc_4));
            return;
        }// end function

        public function hasTypeValue(param1:int, param2:Object) : Boolean
        {
            var _loc_3:Object = null;
            if (this._obj == null)
            {
                return false;
            }
            for each (_loc_3 in this._obj)
            {
                
                if (_loc_3 != null && _loc_3["t"] == param1 && _loc_3["v"] == param2)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function getData(param1:int) : Object
        {
            return this._obj[param1];
        }// end function

        public function removeShortcut(param1:int) : void
        {
            this._obj[param1] = null;
            delete this._obj[param1];
            return;
        }// end function

        public function save() : void
        {
            var _loc_1:Object = {};
            _loc_1["type"] = SystemSettingType.ShortcutBarData;
            _loc_1["value"] = JSON.stringify(this._obj);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

    }
}
